

<!doctype html>
<html ng-app="myReverseFilterApp">
<head>
    <script src="http://code.angularjs.org/1.2.25/angular.min.js"></script>
</head>
<body>
<div ng-controller="MyController">
    <input ng-model="greeting" type="text"><br>
    未添加过滤器: {{greeting}}<br>
    逆置: {{greeting|reverse}}<br>
    逆置 + 大写: {{greeting|reverse:true}}<br>
</div>
</body>
<script type="text/javascript">


    angular.module('myReverseFilterApp', [])
        .filter('reverse', function() {
            return function(input, uppercase) {
                input = input || '';
                var out = '';
                for (var i = 0; i < input.length; i++) {
                    out = input.charAt(i) + out;
                }
                // conditional based on optional argument
                if (uppercase) {
                    out = out.toUpperCase();
                }
                return out;
            };
        })
        .controller('MyController', ['$scope', 'reverseFilter', function($scope, reverseFilter) {
            $scope.greeting = 'hello';
            $scope.filteredGreeting = reverseFilter($scope.greeting);
        }]);


</script>
</html>

